diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-12-30 09:59:47 -0700 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-12-30 09:59:47 -0700 |
commit | 9e6dc529833d17374a73bae1f30c7970f936f7cc (patch) | |
tree | df46666b06065d6aefaf64e5722b57ff07f0a9e8 | |
parent | 00fb7e6f65faf72a85c72f3775e49345aeb7442f (diff) | |
download | stage-9e6dc529833d17374a73bae1f30c7970f936f7cc.tar.gz stage-9e6dc529833d17374a73bae1f30c7970f936f7cc.tar.bz2 stage-9e6dc529833d17374a73bae1f30c7970f936f7cc.tar.xz stage-9e6dc529833d17374a73bae1f30c7970f936f7cc.zip |
Functions exists/delete work now.
-rw-r--r-- | src/astfunction.cpp | 2 | ||||
-rw-r--r-- | src/astfunction.h | 2 | ||||
-rw-r--r-- | src/function.h | 2 | ||||
-rw-r--r-- | src/functiondelete.cpp | 19 | ||||
-rw-r--r-- | src/functiondelete.h | 16 | ||||
-rw-r--r-- | src/functiondisplay.cpp | 2 | ||||
-rw-r--r-- | src/functiondisplay.h | 2 | ||||
-rw-r--r-- | src/functionexists.cpp | 19 | ||||
-rw-r--r-- | src/functionexists.h | 16 | ||||
-rw-r--r-- | src/game.cpp | 4 | ||||
-rw-r--r-- | src/gamestate.cpp | 40 | ||||
-rw-r--r-- | src/gamestate.h | 2 | ||||
-rw-r--r-- | test.stage | 4 |
13 files changed, 125 insertions, 5 deletions
diff --git a/src/astfunction.cpp b/src/astfunction.cpp index f5e25dc..c37a70d 100644 --- a/src/astfunction.cpp +++ b/src/astfunction.cpp | |||
@@ -14,7 +14,7 @@ AstFunction::~AstFunction() | |||
14 | delete pAst; | 14 | delete pAst; |
15 | } | 15 | } |
16 | 16 | ||
17 | Variable AstFunction::call( class GameState &gState ) | 17 | void AstFunction::call( class GameState &gState ) |
18 | { | 18 | { |
19 | gState.parse( pAst ); | 19 | gState.parse( pAst ); |
20 | } | 20 | } |
diff --git a/src/astfunction.h b/src/astfunction.h index a546b19..5e71753 100644 --- a/src/astfunction.h +++ b/src/astfunction.h | |||
@@ -10,7 +10,7 @@ public: | |||
10 | virtual ~AstFunction(); | 10 | virtual ~AstFunction(); |
11 | 11 | ||
12 | virtual Bu::String getName() const { return sName; } | 12 | virtual Bu::String getName() const { return sName; } |
13 | virtual Variable call( class GameState &gState ); | 13 | virtual void call( class GameState &gState ); |
14 | 14 | ||
15 | void addParam( const Bu::String &sName ); | 15 | void addParam( const Bu::String &sName ); |
16 | const Bu::StringList &getParamList() { return lParam; } | 16 | const Bu::StringList &getParamList() { return lParam; } |
diff --git a/src/function.h b/src/function.h index c1289f4..6696d5a 100644 --- a/src/function.h +++ b/src/function.h | |||
@@ -11,7 +11,7 @@ public: | |||
11 | virtual ~Function(); | 11 | virtual ~Function(); |
12 | 12 | ||
13 | virtual Bu::String getName() const=0; | 13 | virtual Bu::String getName() const=0; |
14 | virtual Variable call( class GameState &gState )=0; | 14 | virtual void call( class GameState &gState )=0; |
15 | }; | 15 | }; |
16 | 16 | ||
17 | #endif | 17 | #endif |
diff --git a/src/functiondelete.cpp b/src/functiondelete.cpp new file mode 100644 index 0000000..c9bfef4 --- /dev/null +++ b/src/functiondelete.cpp | |||
@@ -0,0 +1,19 @@ | |||
1 | #include "functiondelete.h" | ||
2 | |||
3 | #include "gamestate.h" | ||
4 | |||
5 | FunctionDelete::FunctionDelete() | ||
6 | { | ||
7 | } | ||
8 | |||
9 | FunctionDelete::~FunctionDelete() | ||
10 | { | ||
11 | } | ||
12 | |||
13 | void FunctionDelete::call( class GameState &gState ) | ||
14 | { | ||
15 | Variable v = gState.pop(); | ||
16 | VariableRef r = v.getVariableRef(); | ||
17 | gState.delVariable( r.sName, r.sid ); | ||
18 | } | ||
19 | |||
diff --git a/src/functiondelete.h b/src/functiondelete.h new file mode 100644 index 0000000..3545343 --- /dev/null +++ b/src/functiondelete.h | |||
@@ -0,0 +1,16 @@ | |||
1 | #ifndef FUNCTION_DELETE_H | ||
2 | #define FUNCTION_DELETE_H | ||
3 | |||
4 | #include "function.h" | ||
5 | |||
6 | class FunctionDelete : public Function | ||
7 | { | ||
8 | public: | ||
9 | FunctionDelete(); | ||
10 | virtual ~FunctionDelete(); | ||
11 | |||
12 | virtual Bu::String getName() const { return "delete"; } | ||
13 | virtual void call( class GameState &gState ); | ||
14 | }; | ||
15 | |||
16 | #endif | ||
diff --git a/src/functiondisplay.cpp b/src/functiondisplay.cpp index 332a2c9..fa5b79c 100644 --- a/src/functiondisplay.cpp +++ b/src/functiondisplay.cpp | |||
@@ -13,7 +13,7 @@ FunctionDisplay::~FunctionDisplay() | |||
13 | { | 13 | { |
14 | } | 14 | } |
15 | 15 | ||
16 | Variable FunctionDisplay::call( class GameState &gState ) | 16 | void FunctionDisplay::call( class GameState &gState ) |
17 | { | 17 | { |
18 | Variable v = gState.popDeref(); | 18 | Variable v = gState.popDeref(); |
19 | sio << "Display: " << v << sio.nl; | 19 | sio << "Display: " << v << sio.nl; |
diff --git a/src/functiondisplay.h b/src/functiondisplay.h index d1a63a9..3b7e828 100644 --- a/src/functiondisplay.h +++ b/src/functiondisplay.h | |||
@@ -10,7 +10,7 @@ public: | |||
10 | virtual ~FunctionDisplay(); | 10 | virtual ~FunctionDisplay(); |
11 | 11 | ||
12 | virtual Bu::String getName() const { return "display"; } | 12 | virtual Bu::String getName() const { return "display"; } |
13 | virtual Variable call( class GameState &gState ); | 13 | virtual void call( class GameState &gState ); |
14 | }; | 14 | }; |
15 | 15 | ||
16 | #endif | 16 | #endif |
diff --git a/src/functionexists.cpp b/src/functionexists.cpp new file mode 100644 index 0000000..71e03f6 --- /dev/null +++ b/src/functionexists.cpp | |||
@@ -0,0 +1,19 @@ | |||
1 | #include "functionexists.h" | ||
2 | |||
3 | #include "gamestate.h" | ||
4 | |||
5 | FunctionExists::FunctionExists() | ||
6 | { | ||
7 | } | ||
8 | |||
9 | FunctionExists::~FunctionExists() | ||
10 | { | ||
11 | } | ||
12 | |||
13 | void FunctionExists::call( class GameState &gState ) | ||
14 | { | ||
15 | Variable v = gState.pop(); | ||
16 | VariableRef r = v.getVariableRef(); | ||
17 | gState.push( Variable( gState.hasVariable( r.sName, r.sid ) ) ); | ||
18 | } | ||
19 | |||
diff --git a/src/functionexists.h b/src/functionexists.h new file mode 100644 index 0000000..5313331 --- /dev/null +++ b/src/functionexists.h | |||
@@ -0,0 +1,16 @@ | |||
1 | #ifndef FUNCTION_EXISTS_H | ||
2 | #define FUNCTION_EXISTS_H | ||
3 | |||
4 | #include "function.h" | ||
5 | |||
6 | class FunctionExists : public Function | ||
7 | { | ||
8 | public: | ||
9 | FunctionExists(); | ||
10 | virtual ~FunctionExists(); | ||
11 | |||
12 | virtual Bu::String getName() const { return "exists"; } | ||
13 | virtual void call( class GameState &gState ); | ||
14 | }; | ||
15 | |||
16 | #endif | ||
diff --git a/src/game.cpp b/src/game.cpp index 6c980ee..87d82b7 100644 --- a/src/game.cpp +++ b/src/game.cpp | |||
@@ -1,10 +1,14 @@ | |||
1 | #include "game.h" | 1 | #include "game.h" |
2 | 2 | ||
3 | #include "functiondisplay.h" | 3 | #include "functiondisplay.h" |
4 | #include "functionexists.h" | ||
5 | #include "functiondelete.h" | ||
4 | 6 | ||
5 | Game::Game() | 7 | Game::Game() |
6 | { | 8 | { |
7 | addFunction( new FunctionDisplay() ); | 9 | addFunction( new FunctionDisplay() ); |
10 | addFunction( new FunctionExists() ); | ||
11 | addFunction( new FunctionDelete() ); | ||
8 | } | 12 | } |
9 | 13 | ||
10 | Game::~Game() | 14 | Game::~Game() |
diff --git a/src/gamestate.cpp b/src/gamestate.cpp index 902d0a9..a3758ce 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp | |||
@@ -65,6 +65,46 @@ void GameState::callFunction( const Bu::String &sName ) | |||
65 | pGame->getFunction( sName )->call( *this ); | 65 | pGame->getFunction( sName )->call( *this ); |
66 | } | 66 | } |
67 | 67 | ||
68 | bool GameState::hasVariable( const Bu::String &sName, ScopeId id ) | ||
69 | { | ||
70 | switch( id ) | ||
71 | { | ||
72 | case sidLocal: | ||
73 | return lsLocal.peek()->has( sName ); | ||
74 | |||
75 | case sidGlobal: | ||
76 | return sGlobal.has( sName ); | ||
77 | |||
78 | case sidPlayer: | ||
79 | return sPlayer.has( sName ); | ||
80 | |||
81 | case sidSituation: | ||
82 | return hsSituation.get( sCurSituation )->has( sName ); | ||
83 | } | ||
84 | |||
85 | throw Bu::ExceptionBase("Really bad scopeid passed into getVariable"); | ||
86 | } | ||
87 | |||
88 | void GameState::delVariable( const Bu::String &sName, ScopeId id ) | ||
89 | { | ||
90 | switch( id ) | ||
91 | { | ||
92 | case sidLocal: | ||
93 | return lsLocal.peek()->erase( sName ); | ||
94 | |||
95 | case sidGlobal: | ||
96 | return sGlobal.erase( sName ); | ||
97 | |||
98 | case sidPlayer: | ||
99 | return sPlayer.erase( sName ); | ||
100 | |||
101 | case sidSituation: | ||
102 | return hsSituation.get( sCurSituation )->erase( sName ); | ||
103 | } | ||
104 | |||
105 | throw Bu::ExceptionBase("Really bad scopeid passed into getVariable"); | ||
106 | } | ||
107 | |||
68 | Variable GameState::getVariable( const Bu::String &sName, ScopeId id ) | 108 | Variable GameState::getVariable( const Bu::String &sName, ScopeId id ) |
69 | { | 109 | { |
70 | try | 110 | try |
diff --git a/src/gamestate.h b/src/gamestate.h index 6000419..61e18e8 100644 --- a/src/gamestate.h +++ b/src/gamestate.h | |||
@@ -26,6 +26,8 @@ public: | |||
26 | 26 | ||
27 | void callFunction( const Bu::String &sName ); | 27 | void callFunction( const Bu::String &sName ); |
28 | 28 | ||
29 | bool hasVariable( const Bu::String &sName, ScopeId id ); | ||
30 | void delVariable( const Bu::String &sName, ScopeId id ); | ||
29 | Variable getVariable( const Bu::String &sName, ScopeId id=sidLocal ); | 31 | Variable getVariable( const Bu::String &sName, ScopeId id=sidLocal ); |
30 | void setVariable( const Bu::String &sName, const Variable &v, ScopeId id=sidLocal ); | 32 | void setVariable( const Bu::String &sName, const Variable &v, ScopeId id=sidLocal ); |
31 | 33 | ||
@@ -48,6 +48,10 @@ situation <<start>> | |||
48 | display("This is the setup phase for start, " + name); | 48 | display("This is the setup phase for start, " + name); |
49 | sillyDisplay( "Hello", name == player.name ); | 49 | sillyDisplay( "Hello", name == player.name ); |
50 | 50 | ||
51 | display( exists(name) ); | ||
52 | delete( name ); | ||
53 | display( exists(name) ); | ||
54 | |||
51 | getThing(); | 55 | getThing(); |
52 | myGoto( <<stuff>> ); | 56 | myGoto( <<stuff>> ); |
53 | display("You shouldn't see this."); | 57 | display("You shouldn't see this."); |